<template>
  <div class="box">
    <div class="title">计算机实验预约管理系统</div>

    <div class="logout">
      <el-dropdown trigger="click">
        <div class="avatar-container">
          <el-icon size="24"><Setting /></el-icon>
          <i-ep-caret-bottom class="w-3 h-3" />
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item divided @click="logout">
              {{ $t("navbar.logout") }}
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
    <div class="content">
      <ul>
        <li @click="change(0)" :class="{ active: index == 0 }">预约申请</li>
        <li @click="change(1)" :class="{ active: index == 1 }">我的预约</li>
        <li @click="change(2)" :class="{ active: index == 2 }">预约记录</li>
        <li @click="change(3)" :class="{ active: index == 3 }">个人中心</li>
      </ul>
      <div style="padding-top: 60px">
        <div v-if="index == 0">
          <el-tabs type="border-card" class="demo-tabs">
            <el-tab-pane label="实验室座位预约"> <Application /></el-tab-pane>
            <el-tab-pane label="实验室资源预约">
              <ResourceApplication
            /></el-tab-pane>
          </el-tabs>
        </div>
        <div v-if="index == 1">
          <el-tabs type="border-card" class="demo-tabs">
            <el-tab-pane label="实验室座位预约"><Booking /></el-tab-pane>
            <el-tab-pane label="实验室资源预约">
              <ResourceBooking
            /></el-tab-pane>
          </el-tabs>
        </div>
        <div v-if="index == 2">
          <el-tabs type="border-card" class="demo-tabs">
            <el-tab-pane label="实验室座位预约记录"> <Record /></el-tab-pane>
            <el-tab-pane label="实验室资源预约记录">
              <ResourceRecord
            /></el-tab-pane>
          </el-tabs>
        </div>
        <div v-if="index == 3">
          <Info />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import Application from "./components/application.vue";
import { ref } from "vue";
import { Setting } from "@element-plus/icons-vue";
import { storeToRefs } from "pinia";
import { useRoute, useRouter } from "vue-router";
import { useAppStore } from "@/store/modules/app";
import { useTagsViewStore } from "@/store/modules/tagsView";
import { useUserStore } from "@/store/modules/user";

const appStore = useAppStore();
const tagsViewStore = useTagsViewStore();
const userStore = useUserStore();

const route = useRoute();
const router = useRouter();
const index = ref(0);

const change = (i: number) => {
  index.value = i;
};

function logout() {
  ElMessageBox.confirm("确定注销并退出系统吗？", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    userStore
      .logout()
      .then(() => {
        tagsViewStore.delAllViews();
      })
      .then(() => {
        router.push(`/login?redirect=${route.fullPath}`);
      });
  });
}
</script>

<style lang="scss" scoped>
.box {
  color: #fb8985;
  padding: 10px 5%;
  background: url("@/assets/images/client-bg.jpg") no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 100vh;
  position: relative;
  .logout {
    position: absolute;
    top: 20px;
    right: 20px;
  }
  .title {
    font-size: 30px;
    text-align: center;
  }
  .content {
    height: 90%;
    background-color: rgba(255, 255, 255, 0.7);
    .active {
      background-color: #f57160;
      color: #fff;
    }

    ul li {
      float: left;
      width: 10%;
      border: 1px solid #ec5d4b;
      height: 45px;
      line-height: 45px;
      text-align: center;
    }
  }
}
</style>
